package com.jams.goodox.activity.serve.enterprise;

import android.widget.RelativeLayout;
import android.widget.TextView;

import com.github.lzyzsd.library.BridgeWebView;
import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.resp.OneKeyServiceResp;
import com.jams.goodox.net.RetrofitCallbackListener;
import com.jams.goodox.net.services.EnterpriseService;
import com.jams.goodox.utils.permission.PhoneUtils;
import com.jams.goodox.utils.StringUtils;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.utils.WebViewUtils;

import butterknife.Bind;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * 代办服务的每个具体内容 type = 7,一键服务
 */
public class OneKeyServiceActivity extends BaseActivity {


    public static final String ONE_KEY_SUB_ID = "ONE_KEY_SUB_ID";
    public static final String ONE_KEY_SERVICE_NAME = "ONE_KEY_SERVICE_NAME";
    @Bind(R.id.tv_enterprise_name)
    TextView mTvEnterpriseName;
    @Bind(R.id.tv_enterprise_time)
    TextView mTvEnterpriseTime;
    @Bind(R.id.rl_enterprise)
    RelativeLayout mRlEnterprise;
    @Bind(R.id.tv_phone)
    TextView mTvPhone;
    @Bind(R.id.tv_service_content)
    TextView mTvServiceContent;
    @Bind(R.id.wv_mentor)
    BridgeWebView mWvMentor;


    /**
     * 传入的subid
     */
    private String subId;
    /**
     * 商家名称
     */

    private String  shopName;
    /**
     * 商家电话
     */
    
    private String subPhone;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_agent_service_item;
    }

    @Override
    protected void init() {
        subId =  StringUtils.newString(getIntent().getStringExtra(ONE_KEY_SUB_ID));
      
        StyleUtil.titleBackKey(this, StringUtils.newString(getIntent().getStringExtra(ONE_KEY_SERVICE_NAME)));
        requestData();
        /*mTvEnterpriseName.setText(mServerBean.getCustomName());
        WebViewUtils.setWebOnlyBody(mWvMentor,StringUtils.newString(mServerBean.getSubUrl()));*/
    }

    @OnClick(R.id.tv_phone)
    public void onViewClicked() {
        new PhoneUtils(mContext).makeCall(StringUtils.newString(shopName),StringUtils.newString(subPhone));
    }

    /**
     * 请求数据
     */
    private void requestData(){
        showLoading();
        enqueue(createCallService(EnterpriseService.class).getOneKeyService(subId), new RetrofitCallbackListener<OneKeyServiceResp>() {
            @Override
            public void onSuccess(Call<OneKeyServiceResp> call, OneKeyServiceResp result) {
                misLoading();
                try {
                    OneKeyServiceResp.DataBean dataBean = result.getData();
                    if (dataBean == null) {
                        return;
                    }
                    shopName = dataBean.getShopName();
                    subPhone = dataBean.getSubPhone();
                    StringBuilder sb = new StringBuilder();
                    sb.append("服务时间: ").append(dataBean.getStartTime()).append("-").append(dataBean.getEndTime());
                    mTvEnterpriseName.setText(shopName);
                    mTvEnterpriseTime.setText(sb);
                    WebViewUtils.setWebOnlyBody(mWvMentor,StringUtils.newString(dataBean.getSubIntroduce()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(String msg) {
                misLoading();
            }
        });
    }

    
}
